class Bullet:
    def __init__(self, damage):
        self.damage = damage    # 伤害力
    # 伤害敌人
    def hurt(self, enemy):
        # 敌人掉血
        enemy.lose_blood(self.damage)

class Clip:
    def __init__(self, capacity):
        self.capacity = capacity    # 子弹的最大容量
        self.current_list = []      # 当前的子弹数量
    # 安装子弹
    def save_bullets(self, bullet):
        if len(self.current_list) < self.capacity:
            self.current_list.append(bullet)
    def __str__(self):
        return f"弹夹当前的子弹数量为:{len(self.current_list)}/{self.capacity}"
    # 出子弹
    def launch_bullet(self):
        # 判断是否还有子弹
        if len(self.current_list) > 0:
            bullet = self.current_list[-1]
            self.current_list.pop()
            return bullet
        else:
            return None

class Gun:
    def __init__(self):
        self.clip = None    # 默认没有弹夹
    def __str__(self):
        if self.clip:
            return "枪当前有弹夹"
        else:
            return "枪没有弹夹"
    # 给枪上弹夹
    def mounting_clip(self, clip):
        if not self.clip:
            self.clip = clip
    # 射击
    def shoot(self, enemy):
        bullet = self.clip.launch_bullet()
        if bullet:
            bullet.hurt(enemy)
        else:
            print("没有子弹了,放了空枪...")

class Person:
    def __init__(self, name):
        self.name = name    # 姓名
        self.blood = 100    # 血量
    # 给弹夹安装子弹
    def install_bullet(self, clip, bullet):
        clip.save_bullets(bullet)
    # 给枪安装弹夹
    def install_clip(self, gun, clip):
        gun.mounting_clip(clip)     # 枪连上弹夹
    # 拿枪
    def take_gun(self, gun):
        self.gun = gun
    # 开枪
    def fire(self, enemy):
        self.gun.shoot(enemy)
    def __str__(self):
        return f"{self.name}剩余血量为:{self.blood}"
    def lose_blood(self, damage):
        self.blood -= damage

# 创建战士
soldier = Person("老王")
# 创建弹夹
clip = Clip(20)
# 上5发子弹
i = 0
while i < 5:
    # 创建子弹
    bullet = Bullet(5)
    # 添加1发子弹
    soldier.install_bullet(clip, bullet)
    i += 1
# 展示弹夹
print(clip)
# 创建一支枪
gun = Gun()
print(gun)
# 装弹夹
soldier.install_clip(gun, clip)
print(gun)
# 创建一个敌人
enemy = Person("敌人")
print(enemy)
# 士兵拿枪
soldier.take_gun(gun)
# 士兵开枪
soldier.fire(enemy)
print(clip)
print(enemy)
soldier.fire(enemy)
print(clip)
print(enemy)
